//神杀
import { GanZhi } from './ganzhi';
import { SiZhu } from './sizhu';
import { vssinfo, getSSItemInfo } from './shenshainfo';

export class shenSha {
	/**
	 * @description 天乙贵人
	 * @param {GanZhi} theDayGZ
	 * @param {GanZhi} theGanZhi
	 * @return {Boolean}
	 */
	static getSSTianYi(theDayGZ : GanZhi, theGanZhi : GanZhi) : boolean {
		var dDiZhiText = theGanZhi.getDiZhiText();
		switch (theDayGZ.getTianGanText()) {
			case "甲":
			case "戊":
				if (dDiZhiText == "丑" || dDiZhiText == "未") return true;
				break;
			case "乙":
			case "己":
				if (dDiZhiText == "子" || dDiZhiText == "申") return true;
				break;
			case "丙":
			case "丁":
				if (dDiZhiText == "亥" || dDiZhiText == "酉") return true;
				break;
			case "壬":
			case "癸":
				if (dDiZhiText == "卯" || dDiZhiText == "巳") return true;
				break;
			case "庚":
			case "辛":
				if (dDiZhiText == "寅" || dDiZhiText == "午") return true;
				break;
		}
		return false;
	}

	/**
	 * @description 天德贵人
	 * @param {GanZhi} theMonthGZ
	 * @param {GanZhi} theGanZhi
	 */
	static getSSTianDe(theMonthGZ : GanZhi, theGanZhi : GanZhi) : boolean {
		var dtext = theGanZhi.getTianGanText();
		var ddztext = theGanZhi.getDiZhiText();
		switch (theMonthGZ.DiZhi) {
			case 2:
				if (dtext == "丁") return true;
				break;
			case 3:
				if (ddztext == "申") return true;
				break;
			case 4:
				if (dtext == "壬") return true;
				break;
			case 5:
				if (dtext == "辛") return true;
				break;
			case 6:
				if (ddztext == "亥") return true;
				break;
			case 7:
				if (dtext == "甲") return true;
				break;
			case 8:
				if (dtext == "癸") return true;
				break;
			case 9:
				if (ddztext == "寅") return true;
				break;
			case 10:
				if (dtext == "丙") return true;
				break;
			case 11:
				if (dtext == "乙") return true;
				break;
			case 0:
				if (ddztext == "巳") return true;
				break;
			case 1:
				if (dtext == "庚") return true;
				break;
		}
		return false;
	}

	/**
	 * @description 月德贵人
	 * @param {GanZhi} theMonthGZ
	 * @param {GanZhi} theGanZhi
	 */
	static getSSYueDe(theMonthGZ : GanZhi, theGanZhi : GanZhi) : boolean {
		var dtext = theGanZhi.getTianGanText();
		switch (theMonthGZ.getDiZhiText()) {
			case "寅":
			case "午":
			case "戌":
				if (dtext == "丙") return true;
				break;
			case "申":
			case "子":
			case "辰":
				if (dtext == "壬") return true;
				break;
			case "亥":
			case "卯":
			case "未":
				if (dtext == "甲") return true;
				break;
			case "巳":
			case "酉":
			case "丑":
				if (dtext == "庚") return true;
				break;
		}
		return false;
	}

	/**
	 * @description 三奇贵人
	 * @param {SiZhu} theSZ
	 */
	static getSSSanQi(theSZ : SiZhu) : boolean {
		var dtext = theSZ.YearGZ.getTianGanText() + theSZ.MonthGZ.getTianGanText() + theSZ.DayGZ.getTianGanText();
		if (theSZ.HourGZ != null) dtext += theSZ.HourGZ.getTianGanText();
		if (dtext.indexOf("乙丙丁") > 0) return true;
		if (dtext.indexOf("丁丙乙") > 0) return true;
		dtext = theSZ.YearGZ.getDiZhiText() + theSZ.MonthGZ.getDiZhiText() + theSZ.DayGZ.getDiZhiText();
		if (theSZ.HourGZ != null) dtext += theSZ.HourGZ.getDiZhiText();
		if (dtext.indexOf("卯巳午") > 0) return true;
		if (dtext.indexOf("午巳卯") > 0) return true;

		return false;
	}

	/**
	 * @description 魁罡贵人
	 * @param {GanZhi} theDayGZ
	 */
	static getSSKuiGang(theDayGZ : GanZhi) : boolean {
		switch (theDayGZ.getText()) {
			case "壬辰":
			case "庚戌":
			case "庚辰":
			case "戊戌":
				return true;
		}
		return false;
	}

	/**
	 * @description 孤辰寡宿
	 * @param {GanZhi} theYearGZ
	 * @param {GanZhi} theGanZhi
	 */
	static getSSGuGua(theIsMan : GanZhi, theYearGZ : GanZhi, theGanZhi : GanZhi) : boolean {
		var dtext = theGanZhi.getDiZhiText();
		switch (theYearGZ.getDiZhiText()) {
			case "亥":
			case "子":
			case "丑":
				if (theIsMan && dtext == "寅") return true;
				if (!theIsMan && dtext == "戌") return false;
				break;
			case "寅":
			case "卯":
			case "辰":
				if (theIsMan && dtext == "巳") return true;
				if (!theIsMan && dtext == "丑") return false;
				break;
			case "巳":
			case "午":
			case "未":
				if (theIsMan && dtext == "申") return true;
				if (!theIsMan && dtext == "辰") return false;
				break;
			case "申":
			case "酉":
			case "戌":
				if (theIsMan && dtext == "亥") return true;
				if (!theIsMan && dtext == "未") return false;
				break;
		}
		return false;
	}

	/**
	 * @description 阴阳差错
	 * @param {GanZhi} theDayGZ
	 */
	static getSSYinYangChaCuo(theDayGZ : GanZhi) : boolean {
		switch (theDayGZ.getText()) {
			case "丙子":
			case "丁丑":
			case "戊寅":
			case "辛卯":
			case "壬辰":
			case "癸巳":
			case "丙午":
			case "丁未":
			case "戊申":
			case "辛酉":
			case "壬戌":
			case "癸亥":
				return true;
		}
		return false;
	}

	/**
	 * @description 十恶大败
	 * @param {GanZhi} theDayGZ
	 */
	static getSSShiEDaBai(theDayGZ : GanZhi) : boolean {
		switch (theDayGZ.getText()) {
			case "甲辰":
			case "乙巳":
			case "壬申":
			case "丙申":
			case "丁亥":
			case "庚辰":
			case "戊戌":
			case "癸亥":
			case "辛巳":
			case "己丑":
				return true;
		}
		return false;
	}

	/**
	 * @description 孤鸾煞
	 * @param {GanZhi} theDayGZ
	 * @param {GanZhi} theHourGZ
	 */
	static getSSGuLuan(theDayGZ : GanZhi, theHourGZ : GanZhi) : boolean {
		if (theHourGZ == null) return false;
		var ddaytext = theDayGZ.getText();
		var dhourtext = theHourGZ.getText();
		if (ddaytext == dhourtext) return false;
		var dday = false,
			dhour = false;
		switch (ddaytext) {
			case "乙巳":
			case "丁巳":
			case "辛亥":
			case "戊申":
			case "壬寅":
			case "戊午":
			case "壬子":
			case "丙午":
				dday = true;
				break;
		}
		switch (dhourtext) {
			case "乙巳":
			case "丁巳":
			case "辛亥":
			case "戊申":
			case "壬寅":
			case "戊午":
			case "壬子":
			case "丙午":
				dhour = true;
				break;
		}
		return (dday && dhour);
	}

	/**
	 * @description 驿马
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSYiMa(theSiZhu : SiZhu) : string[] {
		var dy = theSiZhu.YearGZ.getDiZhiText();
		var dm = theSiZhu.MonthGZ.getDiZhiText();
		var dd = theSiZhu.DayGZ.getDiZhiText();
		var dh = "";
		if (theSiZhu.HourGZ) dh = theSiZhu.HourGZ.getDiZhiText();

		var darray = new Array({
			a: "申子辰",
			b: "寅"
		}, {
			a: "寅午戌",
			b: "申"
		}, {
			a: "巳酉丑",
			b: "亥"
		}, {
			a: "亥卯未",
			b: "巳"
		});
		var res = new Array();

		var yok = false, mok = false, dok = false, hok = false;
		for (var xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(dy) >= 0) {
				if (dm == darray[xx].b) mok = true;
				if (dd == darray[xx].b) dok = true;
				if (dh == darray[xx].b) hok = true;
			}
			if (darray[xx].a.indexOf(dd) >= 0) {
				if (dy == darray[xx].b) yok = true;
				if (dm == darray[xx].b) mok = true;
				if (dh == darray[xx].b) hok = true;
			}
		}

		if (yok) res.push("年见驿马")
		if (mok) res.push("月见驿马")
		if (dok) res.push("日见驿马")
		if (hok) res.push("时见驿马")
		return res;
	}

	/**
	 * 学堂词馆,返回文字数组
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSXueTangCiGuan(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "甲",
			b: "亥寅"
		}, {
			a: "丙戊",
			b: "寅巳"
		}, {
			a: "庚",
			b: "巳申"
		}, {
			a: "壬",
			b: "申亥"
		}, {
			a: "乙",
			b: "午卯"
		}, {
			a: "丁已",
			b: "酉午"
		}, {
			a: "辛",
			b: "子酉"
		}, {
			a: "癸",
			b: "卯子"
		})
		var day = theSiZhu.DayGZ.getTianGanText();
		var mdz = theSiZhu.MonthGZ.getDiZhiText();
		var hdz = "";
		if (theSiZhu.HourGZ) hdz = theSiZhu.HourGZ.getDiZhiText();
		for (var xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(day) >= 0) {
				if (darray[xx].b.indexOf(mdz) == 0) res.push("月见学堂");
				if (darray[xx].b.indexOf(mdz) == 1) res.push("月见词馆");
				if (hdz != "") {
					if (darray[xx].b.indexOf(hdz) == 0) res.push("时见学堂");
					if (darray[xx].b.indexOf(hdz) == 1) res.push("时见词馆");
				}
				break;
			}
		}
		return res;
	}

	/**
	 * 华盖
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSHuaGai(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "寅午戌",
			b: "戌"
		}, {
			a: "亥卯未",
			b: "未"
		}, {
			a: "申子辰",
			b: "辰"
		}, {
			a: "巳酉丑",
			b: "丑"
		})

		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		var yok = false, mok = false, dok = false, hok = false;
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(y) >= 0) {
				if (m == darray[xx].b) mok = true;
				if (d == darray[xx].b) dok = true;
				if (h == darray[xx].b) hok = true;
			}
			if (darray[xx].a.indexOf(d) >= 0) {
				if (y == darray[xx].b) yok = true;
				if (m == darray[xx].b) mok = true;
				if (h == darray[xx].b) hok = true;
			}
		}

		if (yok) res.push("年见华盖")
		if (mok) res.push("月见华盖")
		if (dok) res.push("日见华盖")
		if (hok) res.push("时见华盖")
		return res;
	}

	/**
	 * 将星
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSJiangXing(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "寅午戌",
			b: "午"
		}, {
			a: "亥卯未",
			b: "卯"
		}, {
			a: "申子辰",
			b: "子"
		}, {
			a: "巳酉丑",
			b: "酉"
		})

		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		var yok = false, mok = false, dok = false;
		let hok = false;
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(y) >= 0) {
				if (m == darray[xx].b) mok = true;
				if (d == darray[xx].b) dok = true;
				if (h == darray[xx].b) hok = true;
			}
			if (darray[xx].a.indexOf(d) >= 0) {
				if (y == darray[xx].b) yok = true;
				if (m == darray[xx].b) mok = true;
				if (h == darray[xx].b) hok = true;
			}
		}

		if (yok) res.push("年见将星");
		if (mok) res.push("月见将星");
		if (dok) res.push("日见将星");
		if (hok) res.push("时见将星");
		return res;
	}

	/**
	 * 禄神
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSLuShen(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "甲",
			b: "寅"
		}, {
			a: "乙",
			b: "卯"
		}, {
			a: "丙戊",
			b: "巳"
		}, {
			a: "丁己",
			b: "午"
		}, {
			a: "庚",
			b: "申"
		}, {
			a: "辛",
			b: "酉"
		}, {
			a: "壬",
			b: "亥"
		}, {
			a: "癸",
			b: "子"
		})

		var tg = theSiZhu.DayGZ.getTianGanText();
		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(tg) >= 0) {
				if (y == darray[xx].b) res.push("命见岁禄");
				if (m == darray[xx].b) res.push("命见建禄");
				if (d == darray[xx].b) res.push("命见专禄");
				if (h == darray[xx].b) res.push("命见归禄");
				break;
			}
		}

		return res;
	}

	/**
	 * 拱禄
	 * @param {SiZhu} theSiZhu
	 * @return {String}
	 */
	static getSSGongLu(theSiZhu : SiZhu) : string {
		if (!theSiZhu.HourGZ) return "";
		var day = theSiZhu.DayGZ.getText();
		var hour = theSiZhu.HourGZ.getText();
		if (day == "癸亥" && hour == "癸丑" || day == "癸丑" && hour == "癸亥") {
			return "拱子禄";
		} else if (day == "丁巳" && hour == "丁未" || day == "己未" && hour == "己巳") {
			return "拱午禄";
		} else if (day == "戊辰" && hour == "戊午") {
			return "拱巳禄";
		} else {
			return "";
		}
	}

	/**
	 * 天罗地网
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSTianLuoDiWang(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();

		if (y == "辰" && d == "巳" || y == "巳" && d == "辰") res.push("年见地网");
		if (m == "辰" && d == "巳" || m == "巳" && d == "辰") res.push("月见地网");
		if (h == "辰" && d == "巳" || h == "巳" && d == "辰") res.push("时见地网");
		if (y == "戌" && d == "亥" || y == "亥" && d == "戌") res.push("年见天罗");
		if (m == "戌" && d == "亥" || m == "亥" && d == "戌") res.push("月见天罗");
		if (h == "戌" && d == "亥" || h == "亥" && d == "戌") res.push("时见天罗");

		return res;
	}

	/**
	 * 羊刃
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSYangYin(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "甲",
			b: "卯"
		}, {
			a: "乙",
			b: "寅"
		}, {
			a: "丙戊",
			b: "午"
		}, {
			a: "丁己",
			b: "巳"
		}, {
			a: "庚",
			b: "酉"
		}, {
			a: "辛",
			b: "申"
		}, {
			a: "壬",
			b: "子"
		}, {
			a: "癸",
			b: "亥"
		})

		var tg = theSiZhu.DayGZ.getTianGanText();
		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(tg) >= 0) {
				if (y == darray[xx].b) res.push("年见羊刃");
				if (m == darray[xx].b) res.push("月见羊刃");
				if (d == darray[xx].b) res.push("日见羊刃");
				if (h == darray[xx].b) res.push("时见羊刃");
				break;
			}
		}

		return res;
	}

	/**
	 * 金舆
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSJinXin(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "甲",
			b: "辰"
		}, {
			a: "乙",
			b: "巳"
		}, {
			a: "丙戊",
			b: "未"
		}, {
			a: "丁己",
			b: "申"
		}, {
			a: "庚",
			b: "戌"
		}, {
			a: "辛",
			b: "亥"
		}, {
			a: "壬",
			b: "丑"
		}, {
			a: "癸",
			b: "寅"
		})
		var tg = theSiZhu.DayGZ.getTianGanText();
		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(tg) >= 0) {
				if (y == darray[xx].b) res.push("年见金舆");
				if (m == darray[xx].b) res.push("月见金舆");
				if (d == darray[xx].b) res.push("日见金舆");
				if (h == darray[xx].b) res.push("时见金舆");
				break;
			}
		}

		return res;
	}

	/**
	 * 金神
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSJinShen(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		if ("乙丑 己巳 癸酉".indexOf(theSiZhu.DayGZ.getText()) >= 0) res.push("日见金神");
		if ("乙丑 己巳 癸酉".indexOf(theSiZhu.DayGZ.getText()) >= 0) res.push("时见金神");
		return res;
	}

	/**
	 * 亡神,劫煞
	 * @param {Object} theSiZhu
	 */
	static getSSWangShenJieSha(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "寅午戌",
			b: "巳",
			c: "亥"
		}, {
			a: "亥卯未",
			b: "寅",
			c: "申"
		}, {
			a: "申子辰",
			b: "亥",
			c: "巳"
		}, {
			a: "巳酉丑",
			b: "申",
			c: "寅"
		})

		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();

		var y1ok = false, m1ok = false, d1ok = false, h1ok = false;
		var y2ok = false, m2ok = false, d2ok = false, h2ok = false;
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(y) >= 0) {
				if (darray[xx].b == m) m1ok = true;
				if (darray[xx].c == m) m2ok = true;
				if (darray[xx].b == d) d1ok = true;
				if (darray[xx].c == d) d2ok = true;
				if (darray[xx].b == h) h1ok = true;
				if (darray[xx].c == h) h2ok = true;
			}

			if (darray[xx].a.indexOf(d) >= 0) {
				if (darray[xx].b == y) y1ok = true;
				if (darray[xx].c == y) y2ok = true;
				if (darray[xx].b == m) m1ok = true;
				if (darray[xx].c == m) m2ok = true;
				if (darray[xx].b == h) h1ok = true;
				if (darray[xx].c == h) h2ok = true;
			}
		}

		if (y1ok) res.push("年见亡神")
		if (m1ok) res.push("月见亡神")
		if (d1ok) res.push("日见亡神")
		if (h1ok) res.push("时见亡神")
		if (y2ok) res.push("年见劫煞")
		if (m2ok) res.push("月见劫煞")
		if (d2ok) res.push("日见劫煞")
		if (h2ok) res.push("时见劫煞")
		return res;
	}

	/**
	 * 元辰(大耗)
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSYuanChen(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var s1 = "未申酉戌亥子丑寅卯辰巳午";
		var s2 = "巳午未申酉戌亥子丑寅卯辰";
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();

		var i = theSiZhu.YearGZ.DiZhi;
		if (theSiZhu.DaYunSort()) {
			if (s1.indexOf(m) == i) res.push("月见元辰");
			if (s1.indexOf(d) == i) res.push("日见元辰");
			if (h != "" && s1.indexOf(d) == i) res.push("时见元辰");
		} else {
			if (s2.indexOf(m) == i) res.push("月见元辰");
			if (s2.indexOf(d) == i) res.push("日见元辰");
			if (h != "" && s2.indexOf(d) == i) res.push("时见元辰");
		}

		return res;
	}

	/**
	 * 咸池(桃花)
	 * @param {SiZhu} theSiZhu
	 * @return {String[]}
	 */
	static getSSXianChi(theSiZhu : SiZhu) : string[] {
		var res = new Array();
		var darray = new Array({
			a: "寅午戌",
			b: "卯"
		}, {
			a: "亥卯未",
			b: "子"
		}, {
			a: "申子辰",
			b: "酉"
		}, {
			a: "巳酉丑",
			b: "午"
		})

		var y = theSiZhu.YearGZ.getDiZhiText();
		var m = theSiZhu.MonthGZ.getDiZhiText();
		var d = theSiZhu.DayGZ.getDiZhiText();
		var h = "";
		if (theSiZhu.HourGZ) h = theSiZhu.HourGZ.getDiZhiText();
		var yok = false, mok = false, dok = false, hok = false;
		for (let xx = 0; xx < darray.length; xx++) {
			if (darray[xx].a.indexOf(y) >= 0) {
				if (m == darray[xx].b) mok = true;
				if (d == darray[xx].b) dok = true;
				if (h == darray[xx].b) hok = true;
			}
			if (darray[xx].a.indexOf(d) >= 0) {
				if (y == darray[xx].b) yok = true;
				if (m == darray[xx].b) mok = true;
				if (h == darray[xx].b) hok = true;
			}
		}

		if (yok) res.push("年见咸池")
		if (mok) res.push("月见咸池")
		if (dok) res.push("日见咸池")
		if (hok) res.push("时见咸池")
		return res;
	}

	static vssinfo = vssinfo;
	static getSSItemInfo(name : string) : string { return getSSItemInfo(name) };
}